package com.shallwead.bna.Async;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;

import com.shallwead.bna.object.AdTracker;
import com.shallwead.bna.util.JSON;
import com.shallwead.bna.util.Logger;

public class PushClickTelAsync extends AsyncTask<Void, String, Boolean> {

	Context mContext;
	String Url;
	AdTracker adTracker;

	public PushClickTelAsync(Context mContext, String Url, AdTracker adTracker) {
		this.mContext = mContext;
		this.Url = Url;
		this.adTracker = adTracker;
	}

	@Override
	protected Boolean doInBackground(Void... params) {
		return JSON.sendPushClick(mContext, adTracker);
	}

	@Override
	protected void onPostExecute(Boolean result) {
		super.onPostExecute(result);
		Logger.e(Url);
		if (Url.contains("direct")) {
			Url = Url.replace("direct", "");
			mContext.startActivity(new Intent(Intent.ACTION_CALL, Uri
					.parse("tel://" + Url))
					.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
		} else {
			Url = Url.replace("direct", "");
			mContext.startActivity(new Intent(Intent.ACTION_DIAL, Uri
					.parse("tel://" + Url))
					.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
		}

	}
}
